﻿// =================================================================== 
// 项目说明
//====================================================================
// 天网软件股份有限公司
// 文件： SYS_FUNCTION_TABLE.cs
// 项目名称：企业内部管理信息系统


// 创建时间：2013/3/19
// 负责人：
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using TWCommonLib.Model;
using TWCommonLib.IDAL;


//注意：该文件自动生成，一般请不要手工修改。




namespace MSSQLDAL
{
    /// <summary>
    /// 数据层实例化接口类 .
    /// </summary>
    public partial class SYS_FUNCTION_TABLEDAL : ISYS_FUNCTION_TABLEDAL
    {
		
		 #region 变量声明（For update 和 Insert 时）
		// 声明静态变量 
		private const string PARA_SYS_TABLE_KEY =  "@SYS_TABLE_KEY";
		private const string PARA_FUNCTION_ID =  "@FUNCTION_ID";
		private const string PARA_TABLE_NAME =  "@TABLE_NAME";
		private const string PARA_TABLE_SCRIPT =  "@TABLE_SCRIPT";
		private const string PARA_PRIVILEGE_FIELD =  "@PRIVILEGE_FIELD";
		private const string PARA_PRIVILEGE_USE =  "@PRIVILEGE_USE";
		private const string PARA_SYSTEM_STR =  "@SYSTEM_STR";
		private const string PARA_REMARK =  "@REMARK";

		private const string SQL_UPDATE = "UPDATE SYS_FUNCTION_TABLE SET  SYS_TABLE_KEY= @SYS_TABLE_KEY, FUNCTION_ID= @FUNCTION_ID, TABLE_NAME= @TABLE_NAME, TABLE_SCRIPT= @TABLE_SCRIPT, PRIVILEGE_FIELD= @PRIVILEGE_FIELD, PRIVILEGE_USE= @PRIVILEGE_USE, SYSTEM_STR= @SYSTEM_STR, REMARK= @REMARK  WHERE SYS_TABLE_KEY = @SYS_TABLE_KEY ";
		private const string SQL_INSERT = "INSERT INTO SYS_FUNCTION_TABLE(SYS_TABLE_KEY, FUNCTION_ID, TABLE_NAME, TABLE_SCRIPT, PRIVILEGE_FIELD, PRIVILEGE_USE, SYSTEM_STR, REMARK ) values ( @SYS_TABLE_KEY, @FUNCTION_ID, @TABLE_NAME, @TABLE_SCRIPT, @PRIVILEGE_FIELD, @PRIVILEGE_USE, @SYSTEM_STR, @REMARK ) ";
		#endregion
		
		// 查询数据的sql串




		private string TableString;
		
		#region 构造函数




		/// <summary>
		/// ??????
		/// </summary>
		public SYS_FUNCTION_TABLEDAL()
		{
			if (QueryDataString == "")
                TableString = "SYS_FUNCTION_TABLE SQL_A";
            else
                TableString = "(" + QueryDataString + ") SQL_A";
		}
		#endregion

        //-----------实例化接口函数-----------
		
		//------------增删改函数------------------- 
		
		#region Add 向数据库中插入一条新记录。




		/// <summary>
		/// 向数据库SYS_FUNCTION_TABLE中插入一条新记录。




		/// </summary>
		/// <param name="_SYS_FUNCTION_TABLEModel">SYS_FUNCTION_TABLE??</param>
		/// <returns>影响的行数</returns>
		public int Add(TWCommonLib.Model.SYS_FUNCTION_TABLE _SYS_FUNCTION_TABLEModel)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter(PARA_SYS_TABLE_KEY, SqlDbType.Int), 
				new SqlParameter(PARA_FUNCTION_ID, SqlDbType.VarChar), 
				new SqlParameter(PARA_TABLE_NAME, SqlDbType.VarChar), 
				new SqlParameter(PARA_TABLE_SCRIPT, SqlDbType.VarChar), 
				new SqlParameter(PARA_PRIVILEGE_FIELD, SqlDbType.VarChar), 
				new SqlParameter(PARA_PRIVILEGE_USE, SqlDbType.SmallInt), 
				new SqlParameter(PARA_SYSTEM_STR, SqlDbType.VarChar), 
				new SqlParameter(PARA_REMARK, SqlDbType.VarChar)
			};			
			
			 _param[0].Value =  _SYS_FUNCTION_TABLEModel.SYS_TABLE_KEY;
			 _param[1].Value =  _SYS_FUNCTION_TABLEModel.FUNCTION_ID;
			 _param[2].Value =  _SYS_FUNCTION_TABLEModel.TABLE_NAME;
			 _param[3].Value =  _SYS_FUNCTION_TABLEModel.TABLE_SCRIPT;
			 _param[4].Value =  _SYS_FUNCTION_TABLEModel.PRIVILEGE_FIELD;
			 _param[5].Value =  _SYS_FUNCTION_TABLEModel.PRIVILEGE_USE;
			 _param[6].Value =  _SYS_FUNCTION_TABLEModel.SYSTEM_STR;
			 _param[7].Value =  _SYS_FUNCTION_TABLEModel.REMARK;

			
			//  返回
			return (int)SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, SQL_INSERT, _param);


		}
		#endregion
		
		#region Add 向数据库中插入一条新记录。带事务
		/// <summary>
		/// 向数据库SYS_FUNCTION_TABLE中插入一条新记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_SYS_FUNCTION_TABLEModel">SYS_FUNCTION_TABLE实体</param>
		/// <returns>影响的行数</returns>
		public int Add(DBTransaction dbTrans,TWCommonLib.Model.SYS_FUNCTION_TABLE _SYS_FUNCTION_TABLEModel)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter(PARA_SYS_TABLE_KEY, SqlDbType.Int), 
				new SqlParameter(PARA_FUNCTION_ID, SqlDbType.VarChar), 
				new SqlParameter(PARA_TABLE_NAME, SqlDbType.VarChar), 
				new SqlParameter(PARA_TABLE_SCRIPT, SqlDbType.VarChar), 
				new SqlParameter(PARA_PRIVILEGE_FIELD, SqlDbType.VarChar), 
				new SqlParameter(PARA_PRIVILEGE_USE, SqlDbType.SmallInt), 
				new SqlParameter(PARA_SYSTEM_STR, SqlDbType.VarChar), 
				new SqlParameter(PARA_REMARK, SqlDbType.VarChar)
			};	
			
			 _param[0].Value =  _SYS_FUNCTION_TABLEModel.SYS_TABLE_KEY;
			 _param[1].Value =  _SYS_FUNCTION_TABLEModel.FUNCTION_ID;
			 _param[2].Value =  _SYS_FUNCTION_TABLEModel.TABLE_NAME;
			 _param[3].Value =  _SYS_FUNCTION_TABLEModel.TABLE_SCRIPT;
			 _param[4].Value =  _SYS_FUNCTION_TABLEModel.PRIVILEGE_FIELD;
			 _param[5].Value =  _SYS_FUNCTION_TABLEModel.PRIVILEGE_USE;
			 _param[6].Value =  _SYS_FUNCTION_TABLEModel.SYSTEM_STR;
			 _param[7].Value =  _SYS_FUNCTION_TABLEModel.REMARK;

			
			//  返回
			return (int)SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, SQL_INSERT, _param);
		}
		#endregion
		
		#region	Update 向数据表更新一条记录。	
		/// <summary>
		/// 向数据表SYS_FUNCTION_TABLE更新一条记录。




		/// </summary>
		/// <param name="_SYS_FUNCTION_TABLEModel">_SYS_FUNCTION_TABLEModel</param>
		/// <returns>影响的行数</returns>
		public int Update(TWCommonLib.Model.SYS_FUNCTION_TABLE _SYS_FUNCTION_TABLEModel)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter(PARA_SYS_TABLE_KEY, SqlDbType.Int), 
				new SqlParameter(PARA_FUNCTION_ID, SqlDbType.VarChar), 
				new SqlParameter(PARA_TABLE_NAME, SqlDbType.VarChar), 
				new SqlParameter(PARA_TABLE_SCRIPT, SqlDbType.VarChar), 
				new SqlParameter(PARA_PRIVILEGE_FIELD, SqlDbType.VarChar), 
				new SqlParameter(PARA_PRIVILEGE_USE, SqlDbType.SmallInt), 
				new SqlParameter(PARA_SYSTEM_STR, SqlDbType.VarChar), 
				new SqlParameter(PARA_REMARK, SqlDbType.VarChar)
			};	
			
			 _param[0].Value =  _SYS_FUNCTION_TABLEModel.SYS_TABLE_KEY;
			 _param[1].Value =  _SYS_FUNCTION_TABLEModel.FUNCTION_ID;
			 _param[2].Value =  _SYS_FUNCTION_TABLEModel.TABLE_NAME;
			 _param[3].Value =  _SYS_FUNCTION_TABLEModel.TABLE_SCRIPT;
			 _param[4].Value =  _SYS_FUNCTION_TABLEModel.PRIVILEGE_FIELD;
			 _param[5].Value =  _SYS_FUNCTION_TABLEModel.PRIVILEGE_USE;
			 _param[6].Value =  _SYS_FUNCTION_TABLEModel.SYSTEM_STR;
			 _param[7].Value =  _SYS_FUNCTION_TABLEModel.REMARK;
			
			return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, SQL_UPDATE, _param);
		}
		#endregion
		
		#region	Update 向数据表更新一条记录。带事务	
		/// <summary>
		/// 向数据表SYS_FUNCTION_TABLE更新一条记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_SYS_FUNCTION_TABLEModel">_SYS_FUNCTION_TABLEModel</param>
		/// <returns>影响的行数</returns>
		public int Update(DBTransaction dbTrans,TWCommonLib.Model.SYS_FUNCTION_TABLE _SYS_FUNCTION_TABLEModel)
		{
           // 声明参数数组并赋值




		    SqlParameter[] _param=
			{
				new SqlParameter(PARA_SYS_TABLE_KEY, SqlDbType.Int), 
				new SqlParameter(PARA_FUNCTION_ID, SqlDbType.VarChar), 
				new SqlParameter(PARA_TABLE_NAME, SqlDbType.VarChar), 
				new SqlParameter(PARA_TABLE_SCRIPT, SqlDbType.VarChar), 
				new SqlParameter(PARA_PRIVILEGE_FIELD, SqlDbType.VarChar), 
				new SqlParameter(PARA_PRIVILEGE_USE, SqlDbType.SmallInt), 
				new SqlParameter(PARA_SYSTEM_STR, SqlDbType.VarChar), 
				new SqlParameter(PARA_REMARK, SqlDbType.VarChar)
			};		
			
			 _param[0].Value =  _SYS_FUNCTION_TABLEModel.SYS_TABLE_KEY;
			 _param[1].Value =  _SYS_FUNCTION_TABLEModel.FUNCTION_ID;
			 _param[2].Value =  _SYS_FUNCTION_TABLEModel.TABLE_NAME;
			 _param[3].Value =  _SYS_FUNCTION_TABLEModel.TABLE_SCRIPT;
			 _param[4].Value =  _SYS_FUNCTION_TABLEModel.PRIVILEGE_FIELD;
			 _param[5].Value =  _SYS_FUNCTION_TABLEModel.PRIVILEGE_USE;
			 _param[6].Value =  _SYS_FUNCTION_TABLEModel.SYSTEM_STR;
			 _param[7].Value =  _SYS_FUNCTION_TABLEModel.REMARK;
			

			
			return SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, SQL_UPDATE, _param);
		}
		#endregion
		
		#region	Delete 根据主键，删除数据表中的一条记录	
		/// <summary>
		/// 根据主键，删除数据表SYS_FUNCTION_TABLE中的一条记录




		/// </summary>
	    /// <param name="sYS_TABLE_KEY">sYS_TABLE_KEY</param>
		/// <returns>影响的行数</returns>
		public int Delete(int sYS_TABLE_KEY)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter("@sYS_TABLE_KEY", SqlDbType.Int)
			};				
			_param[0].Value = sYS_TABLE_KEY;
			
			string sqlStr="delete from SYS_FUNCTION_TABLE where  SYS_TABLE_KEY=@sYS_TABLE_KEY";
			return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, sqlStr, _param);;
		}
		#endregion
		
		#region	Delete 根据主键，删除数据表中的一条记录 带事务




		/// <summary>
		/// 根据主键，删除数据表SYS_FUNCTION_TABLE中的一条记录 带事务




		/// <param name="sp">事务对象</param>
	    /// <param name="SYS_TABLE_KEY">sYS_TABLE_KEY</param>
		/// <returns>影响的行数</returns>
		public int Delete(DBTransaction dbTrans,int sYS_TABLE_KEY)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter("@sYS_TABLE_KEY", SqlDbType.Int)
			};				
			_param[0].Value = sYS_TABLE_KEY;

			string sqlStr="delete from SYS_FUNCTION_TABLE where  SYS_TABLE_KEY=@sYS_TABLE_KEY";
			return SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, sqlStr,_param);;

		}
		#endregion
		
		#region	DeleteFK 根据条件串，删除数据表中的N条记录	
		/// <summary>
		/// 根据条件串，删除数据表SYS_FUNCTION_TABLE中的N条记录




		/// </summary>
	    /// <param name="sWhere">条件串</param>
		/// <returns>影响的行数</returns>
		public int DeleteFK(string sWhere)
		{
			string  sqlStr="delete from SYS_FUNCTION_TABLE";
			if (sWhere.Length>0)
				sqlStr += " where "+sWhere;
			return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, sqlStr);
		}
		#endregion
		
		#region	DeleteFK 删除数据表中的一条记录,带事务	
		/// <summary>
		/// 删除数据表SYS_FUNCTION_TABLE中的一条记录,带事务




		/// </summary>
		/// <param name="sp">事务对象</param>
	    /// <param name="sWhere">条件串</param>
		/// <returns>影响的行数</returns>
		public int DeleteFK(DBTransaction dbTrans,string sWhere)
		{
			string  sqlStr="delete from SYS_FUNCTION_TABLE";
			if (sWhere.Length>0)
				sqlStr += " where "+sWhere;
			return SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, sqlStr);
		}
		
		#endregion
		
		
		//------------获取数据及模型函数




		
		#region Exists 检测是否存在该主键
		/// <summary>
        /// 检测是否存在该主键
        /// </summary>
        /// <param name="int sYS_TABLE_KEY" 主键列表</param>
        /// <returns>是/否</returns>
		public bool Exists(int sYS_TABLE_KEY)
		{
			
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter("@sYS_TABLE_KEY", SqlDbType.Int)
			};				
			_param[0].Value = sYS_TABLE_KEY;
			
            string sqlStr="select Count(*) from SYS_FUNCTION_TABLE where  SYS_TABLE_KEY=@sYS_TABLE_KEY and SYS_TABLE_KEY=@sYS_TABLE_KEY";
						
            int a=Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConnStr,CommandType.Text,sqlStr,_param));
            if(a>0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

		#endregion

		#region GetModel 根据主键ID,得到数据实体
        /// <summary>
		/// 根据主键ID,得到 sys_function_table 数据实体
		/// </summary>
		/// <param name="int sYS_TABLE_KEY" 主键列表</param>
		/// <returns>sys_function_table 数据实体</returns>
		public TWCommonLib.Model.SYS_FUNCTION_TABLE GetModel(int sYS_TABLE_KEY )
		{
			TWCommonLib.Model.SYS_FUNCTION_TABLE _obj=null;
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter("@sYS_TABLE_KEY", SqlDbType.Int)
			};				
			_param[0].Value = sYS_TABLE_KEY;
			
			string sqlStr="select * from SYS_FUNCTION_TABLE where  SYS_TABLE_KEY=@sYS_TABLE_KEY";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(Conn.SqlConnStr,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=PopulateSYS_FUNCTION_TABLEModelFromDr(dr);
				}
			}
			return _obj;
		}
		#endregion
		
		#region ----根据DataRow,得到 数据实体
		/// <summary>
		/// 得到  sys_function_table 数据实体
		/// </summary>
		/// <param name="row">row</param>
		/// <returns>sys_function_table 数据实体</returns>
		public TWCommonLib.Model.SYS_FUNCTION_TABLE PopulateSYS_FUNCTION_TABLEModelFromDr(DataRow row)
		{
			TWCommonLib.Model.SYS_FUNCTION_TABLE Obj = new TWCommonLib.Model.SYS_FUNCTION_TABLE();
			if(row!=null)
			{
				Obj.SYS_TABLE_KEY = (( row["SYS_TABLE_KEY"])==DBNull.Value)?0:Convert.ToInt32( row["SYS_TABLE_KEY"]);
				Obj.FUNCTION_ID =  row["FUNCTION_ID"].ToString();
				Obj.TABLE_NAME =  row["TABLE_NAME"].ToString();
				Obj.TABLE_SCRIPT =  row["TABLE_SCRIPT"].ToString();
				Obj.PRIVILEGE_FIELD =  row["PRIVILEGE_FIELD"].ToString();
				Obj.PRIVILEGE_USE = (short) row["PRIVILEGE_USE"];
				Obj.SYSTEM_STR =  row["SYSTEM_STR"].ToString();
				Obj.REMARK =  row["REMARK"].ToString();
			}
			else
			{
				return null;
			}
			return Obj;
		}
		#endregion
		
		#region ----根据IDataReader,得到 数据实体
        /// <summary>
		/// 得到  sys_function_table 数据实体
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>sys_function_table 数据实体</returns>
		public TWCommonLib.Model.SYS_FUNCTION_TABLE PopulateSYS_FUNCTION_TABLEModelFromDr(IDataReader dr)
		{
			TWCommonLib.Model.SYS_FUNCTION_TABLE Obj = new TWCommonLib.Model.SYS_FUNCTION_TABLE();
			
				Obj.SYS_TABLE_KEY = (( dr["SYS_TABLE_KEY"])==DBNull.Value)?0:Convert.ToInt32( dr["SYS_TABLE_KEY"]);
				Obj.FUNCTION_ID =  dr["FUNCTION_ID"].ToString();
				Obj.TABLE_NAME =  dr["TABLE_NAME"].ToString();
				Obj.TABLE_SCRIPT =  dr["TABLE_SCRIPT"].ToString();
				Obj.PRIVILEGE_FIELD =  dr["PRIVILEGE_FIELD"].ToString();
				Obj.PRIVILEGE_USE = (short) dr["PRIVILEGE_USE"];
				Obj.SYSTEM_STR =  dr["SYSTEM_STR"].ToString();
				Obj.REMARK =  dr["REMARK"].ToString();
			
			return Obj;
		}
		#endregion
///
		#region GetNewID 通过种子得到唯一ID,对单主键有效单，如果该表为多主键，则返回第一主键
		/// <summary>
        ///  通过种子得到唯一ID,对单主键有效单，如果该表为多主键，则返回第一主键
        /// </summary>
        /// <param name="sYS_TABLE_KEY">sYS_TABLE_KEY</param>
        /// <returns>int</returns>
		public int GetNewID()
		{
			return  DBCommon.GetNewIDForTable("SYS_FUNCTION_TABLE","SYS_FUNCTION_TABLE","");
		}
		#endregion
///
		#region	GetMaxID 得到最大ID	
		/// <summary>
		/// 得到最大ID
		/// </summary>
        /// <param name="sYS_TABLE_KEY">sYS_TABLE_KEY</param>
        /// <returns>int</returns>
		public int GetMaxID()
		{
			return  0;
		}
		#endregion
		
		#region	GetList 得到数据表指定字段列表的所有记录，可排序，
		/// <summary>
		/// 得到数据表SYS_FUNCTION_TABLE所有记录，可排序




		/// </summary>
        /// <param name="sWhere">条件字符串</param>
        /// <param name="sOder">排序字段</param>
		/// <returns>DataSet</returns>
		public DataSet GetList(string sWhere, string sOder)
		{
			string	sqlStr="select * from "+TableString;
				
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			if (sOder.Length > 0)
				sqlStr += " order by " + sOder;
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion

		#region	GetListFS 得到数据表指定字段列表的所有记录，可排序，加工作流状态字段




		/// <summary>
		/// 得到数据表SYS_FUNCTION_TABLE所有记录，可排序，加工作流状态字段




		/// </summary>
        /// <param name="FlowProcessId">流程ID</param>
        /// <param name="sWhere">条件字符串</param>
        /// <param name="sOder">排序字段</param>
		/// <returns>DataSet</returns>
		public DataSet GetListFS(string FlowProcessId, string sWhere, string sOder)
		{
			string	sqlStr="select SQL_A.*, isnull(SQL_B.work_state,'未发送') work_state from "+TableString+" left join view_wfInstance_state SQL_B on SQL_a.work_id=SQL_b.work_id";
				
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			if (sOder.Length > 0)
				sqlStr += " order by " + sOder;
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion


		#region GetPageList 根据条件和页号得到某页的记录集,+排序
		/// <summary>
		/// 根据条件和页号得到某页的记录集,+排序
		/// </summary>
        /// <param name="iPageSize">每页记录数</param>
		/// <param name="iPageIndex">页号</param>
		/// <param name="sWhere">条件字符串</param>
		/// <param name="sOder">排序字段</param>
        /// <returns>DataSet</returns>
		public DataSet GetPageList(int iPageSize,int iPageIndex, string sWhere, string sOder)
		{
			if (sOder.Length <=0)
				sOder = "SYS_TABLE_KEY";
				
			string	sqlStr="select * from (select ROW_NUMBER() OVER(order by "+sOder+" ) as row, * from "+TableString;
			
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			sqlStr += ") SQL1 where row between "+ Convert.ToString(iPageSize*(iPageIndex-1)+1) +" and "+Convert.ToString(iPageSize*iPageIndex);
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion		

		#region GetPageListFS 根据条件和页号得到某页的记录集,+排序，加工作流状态字段




		/// <summary>
		/// 根据条件和页号得到某页的记录集,+排序，加工作流状态字段




		/// </summary>
        /// <param name="FlowProcessId">流程ID</param>
        /// <param name="iPageSize">每页记录数</param>
		/// <param name="iPageIndex">页号</param>
		/// <param name="sWhere">条件字符串</param>
		/// <param name="sOder">排序字段</param>
        /// <returns>DataSet</returns>
		public DataSet GetPageListFS(string FlowProcessId, int iPageSize,int iPageIndex, string sWhere, string sOder)
		{
			if (sOder.Length <=0)
				sOder = "SYS_TABLE_KEY";
				
			string	sqlStr="select * from (select ROW_NUMBER() OVER(order by "+sOder+" ) as row, SQL_A.*,isnull(SQL_B.work_state,'未发送') work_state from "+TableString+" left join view_wfInstance_state SQL_B on sql_a.work_id=sql_b.work_id";
			
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			sqlStr += ") SQL1 where row between "+ Convert.ToString(iPageSize*(iPageIndex-1)+1) +" and "+Convert.ToString(iPageSize*iPageIndex);
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion		
		
		
		#region GetRecorderRowNum 判断某条记录所在的行号
		/// <summary>
		/// 判断某条记录所在的行号，调用者自己计算页号和行号
		/// </summary>
        /// <param name="sWhere">记录显示的条件</param>
        /// <param name="sOder">排序条件</param>
        /// <param name="iPageSize">每页记录数</param>
		/// <param name="主键列表">主键列表，需定位记录的键值</param>
        /// <returns>int 页码</returns>
		public int GetRecorderRowNum(string sWhere, string sOder, int iPageSize, int sYS_TABLE_KEY)
		{
			if (sOder.Length <=0)
				sOder = "SYS_TABLE_KEY";
				
			// 声明参数数组并赋值



			SqlParameter[] _param=
			{
				new SqlParameter("@sYS_TABLE_KEY", SqlDbType.Int)
			};				
			_param[0].Value = sYS_TABLE_KEY;
			
			string	sqlStr="select row from (select ROW_NUMBER() OVER(order by "+sOder+" ) as row, sYS_TABLE_KEY from "+TableString;
			
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
				
			sqlStr = sqlStr + ") SQL1 where  SYS_TABLE_KEY=@sYS_TABLE_KEY";
			return Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConnStr,CommandType.Text,sqlStr,_param));
		}
		#endregion
		
						
		#region GetRecorderCount 得到符合条件记录集的记录条数
		/// <summary>
		/// 得到符合条件记录集的记录条数
		/// </summary>
        /// <param name="FlowProcessId">流程ID</param>
		/// <param name="sWhere">条件字符串</param>
        /// <returns>int 记录数</returns>
		public int GetRecorderCount(string FlowProcessId, string sWhere)
		{
			string sqlStr ="";
			
			if (FlowProcessId.Length > 0)
            	sqlStr="select Count(*) from "+TableString+" left join view_wfInstance_state SQL_B on SQL_a.work_id=SQL_b.work_id";
			else
				sqlStr="select Count(*) from "+TableString;
				
			if (sWhere.Length>0)
				sqlStr += " where " + sWhere;
						
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConnStr,CommandType.Text,sqlStr));
		}
		#endregion				
		
		#region----------自定义实例化接口函数----------
		#endregion
    }
}
